package com.acwing.partition9;

import java.io.*;

/**
 * @author `RKC`
 * @date 2021/12/4 10:53
 */
public class AC873欧拉函数 {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] s = reader.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        while (n-- > 0) {
            int x = Integer.parseInt(reader.readLine().split(" ")[0]);
            writer.write(euler(x) + "\n");
        }
        writer.flush();
    }

    private static int euler(int x) {
        int answer = x;
        //欧拉函数公式：f(n) = n(1 - 1/p1)(1 - 1/p2)(1 - 1/p3)......(1 - 1/pk)
        for (int i = 2; i <= x / i; i++) {
            if (x % i == 0) {
                answer = answer / i * (i - 1);
                while (x % i == 0) x /= i;
            }
        }
        if (x > 1) answer = answer / x * (x - 1);
        return answer;
    }
}
